from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import logging
import re
import htmlparser 

logging.getLogger().setLevel(logging.DEBUG)

data = []


class MainPage(webapp.RequestHandler):
  def get(self):
    self.response.out.write('<html><body>')
    self.response.out.write("""
              <form action="/upload" enctype="multipart/form-data" method="post">
                <div><input type="file" name="hrm"/></div>
                <div><input type="submit" value="Upload"></div>
              </form>
            </body>
          </html>""")


class Upload(webapp.RequestHandler):
  def _parseHRM(self, data):
	  result = {}
	  pattern = re.compile("(\S+)\](.*?)\[", re.DOTALL)
	  sections = re.findall(pattern, data[1:] + "[")
    for (sect, value):
	    result[sect] = value  
  return 
  
  def post(self):
    #data = self.request.get("hrm")
	  self.response.out.write('<html><body>')
	  data = self.request.get("hrm"))

	  self.response.out.write('</body></html>')


class Draw(webapp.RequestHandler):
	def get(self):
	  self.response.out.write('<html><body>')
	  self.response.out.write(data)
	  self.response.out.write('</body></html>')
		 	

application = webapp.WSGIApplication([
    ('/hrm', MainPage),
    ('/upload', Upload),
    ('/draw', Draw)
], debug=True)


def main():
  run_wsgi_app(application)


if __name__ == '__main__':
  main()